home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / fortune.arc / FORTUNE.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1985-06-05  |  2.3 KB  |  81 lines

  1. program GimmieaFortune;
  2. {
  3.  Note:
  4.   This program is in the Public Domain, it is free, and should remain so.
  5.   If you would like to make a contribution,
  6.   it would be much appreciated:
  7.  
  8.                 Write another program and give it away.
  9.  
  10.  
  11.   Program : FORTUNE.COM
  12.   Author  : Grant Gouldon
  13.   Date    : 5/24/85
  14.   Source  : FORTUNE.PAS compiled by Turbo Pascal 3.0
  15.   Purpose :
  16.  
  17.      This program will deliver you a fortune out of a file of fortune cookies
  18.                     i.e. FORTUNE.COK
  19.  
  20.      The file of fortunes MUST have as its first line the number of records
  21.      to follow.  This is an easy way of telling the program how big the file
  22.      is, without having to go the route of fixed length records (which would
  23.      allow both random access, and implicitly knowing the file size, but
  24.      would make for a much much bigger file).
  25.  
  26.      Add more fortunes !
  27.  
  28.      (Just keep that record count updated)
  29.  
  30.      Once we know how big the file is,
  31.      we pick a random number n  <  file size,
  32.      skip n records, then read and print the next one.
  33.  
  34.      If the user gives a numeric argument to fortune, he or she will
  35.      get that many fortunes.  If the argument is non-numeric, some
  36.      help text will be displayed.
  37.  
  38. }
  39.  
  40.  
  41. Var
  42.   FilVar:    text;
  43.   Cookie:    string[255];
  44.   NumRecs,
  45.   N,
  46.   J,
  47.   HowMany,
  48.   Ecode:     integer;
  49.  
  50. begin
  51.   Assign(FilVar,'FORTUNE.COK');
  52.   if ParamCount = 0 then
  53.     HowMany := 1
  54.   else
  55.     begin
  56.       Val(ParamStr(1),HowMany,Ecode);
  57.       if Ecode <> 0 then
  58.         begin
  59.           Writeln('If you come here seeking Fame and Fortune,');
  60.           Writeln('I must tell you that task is too vast for me.');
  61.           Writeln('but ...');
  62.           Writeln('I can do something half vast:');
  63.           Writeln('I will give you your Fortune.');
  64.           Writeln(' ');
  65.           Writeln(' ');
  66.           Writeln('If you say FORTUNE 4    I will give you 4 fortunes.');
  67.           Exit
  68.         end;
  69.     end;
  70.   for J := 1 to HowMany do
  71.   begin
  72.     Reset(FilVar);
  73.     Readln(FilVar,NumRecs);
  74.     for N := 1 to Random(NumRecs) do
  75.     begin
  76.       Readln(filvar);
  77.     end;
  78.     Readln(FilVar,Cookie);
  79.     Writeln(Cookie);
  80.   end;
  81. end.